# -*- coding: utf-8 -*-
from pathlib import Path
from google.protobuf import text_format
import logging
import pdb

from .file_utils import file_exist_or_die

logger = logging.getLogger(__name__)

def build_layer_list(caffe_pb2, protoFile):
    file_exist_or_die(protoFile)
    netParam = caffe_pb2.NetParameter()
    with open(protoFile, 'r') as f:
        text_format.Merge(f.read(), netParam)
    lst = []
    for layer in netParam.layer:
        lst.append(layer)
    return lst

def write_layer_list(caffe_pb2, protoFile, layerList):
    netParam = caffe_pb2.NetParameter()
    netParam.layer.extend(layerList)
    with open(protoFile, 'w') as f:
        f.write(text_format.MessageToString(netParam))
